<template>
  <h1>姓名：{{ name }}</h1>
  <h1>年龄：{{ age }}</h1>
  <h1>薪资：{{ job.j1.salary }}K</h1>
  <button @click="name += '1'">点我修改姓名</button>
  <button @click="age++">点我修改年龄</button>
  <button @click="job.j1.salary++">涨薪</button>
</template>

<script>
import { reactive, toRef, toRefs } from "vue";
export default {
  name: "Demo",
  setup() {
    const person = reactive({
      name: "张三",
      age: 18,
      job: {
        j1: {
          salary: 20,
        },
      },
    });

    // 将对象中的某个属性转成ref对象，并且可以修改
    const name = toRef(person, "name");

    console.log("name", name);

    return {
      // 将对象中的所有属性转成ref对象，并且可以修改
      ...toRefs(person),
    };
  },
};
</script>
